package com.javaProject.controller;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CookieController {

    @GetMapping("/set-cookie")
    public String setCookie(HttpServletResponse response) {
        // 创建cookie对象
        Cookie cookie = new Cookie("cookieName", "cookieValue");

        // 设置cookie的有效期（以秒为单位），如果不需要可以省略此行
        cookie.setMaxAge(60 * 60 );

        // 将cookie添加到响应中
        response.addCookie(cookie);

        return "Cookie has been set!";
    }
}